﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics;

namespace Game1942.Library.View
{
    class EnergyCounterView : IObserver<EnergyCounter> 
    {
        public Animation PlayerAnimation;

        public Vector2 Position;

        //This attribute is used to unwrite of observable
        private IDisposable unsubscriber;

        // Initialize the player
        public void Initialize(Animation animation, Vector2 position)
        {
            PlayerAnimation = animation;
            // Set the starting position of the player around the middle of the screen and to the back
            Position = position; 
        }

        //Suscribe this observer to the list of the observable
        public virtual void Subscribe(IObservable<EnergyCounter> provider)
        {
            if (provider != null)
                unsubscriber = provider.Subscribe(this);
        }

        // Update the player animation
        public void Update(GameTime gameTime)
        {
            PlayerAnimation.Position = Position;
            PlayerAnimation.Update(gameTime);
        }

        // Draw the player
        public void Draw(SpriteBatch spriteBatch)
        {
            PlayerAnimation.Draw(spriteBatch);
        }

        //Provides the observer with new data.
        public void OnNext(EnergyCounter value)
        {
            // se debe dar a conocer el total de energia
            //Console.WriteLine(value.Energy);
  
        }

        //Notifies the observer that the provider has experienced an error condition.
        public void OnError(Exception error)
        {
            //Do nothing
        }

        //Notifies the observer that the provider has finished sending push-based notifications.
        public void OnCompleted()
        {
            unsubscriber.Dispose();
        }


    }
}
